#ifndef _NAND_H_
#define _NAND_H_
 
/*NAND Pins*/
#define	NFCONF  		( *(volatile unsigned int   *)0xB0E00000 ) //nand配置寄存器  
#define	NFCONT  		( *(volatile unsigned int   *)0xB0E00004 ) //nand控制寄存器	
#define	NFCMMD  		( *(volatile unsigned char  *)0xB0E00008 ) //命令寄存器
#define	NFADDR  		( *(volatile unsigned char  *)0xB0E0000C )//地址寄存器
#define	NFDATA  		( *(volatile unsigned char  *)0xB0E00010 )//数据寄存器
#define	NFSTAT  		( *(volatile unsigned int   *)0xB0E00028 )//状态寄存器
 
/* NAND GPIO Pins */
#define MP0_1CON 		( *((volatile unsigned long *)0xE02002E0) )
#define MP0_2CON 		( *((volatile unsigned long *)0xE0200300) )
#define MP0_3CON 		( *((volatile unsigned long *)0xE0200320) )
 
/* 时序相关的设置 			*/
#define TACLS    					  2				
#define TWRPH0   					  1
#define TWRPH1   					  1
 
/* K9F4G08U0B参数 */
/*K9F2G08U0A*/		
#define PAGE_SIZE	2048
#define NAND_SECTOR_SIZE_LP    2048
#define NAND_BLOCK_SIZE	64
 
 
typedef struct nand_id_msg
{
	unsigned char maker_id; 
	unsigned char device_id; 
	unsigned char id_3th;
	unsigned char id_4th;
	unsigned char id_5th;
}nand_id_msg;
 
void wait_idle();//等待忙碌函数
unsigned char read_nand_status();//读状态
void nand_select_chip();//片选
void nand_deselect_chip();//释放片选
void write_cmd(int cmd);//写命令
void write_addr(unsigned int addr);//写地址
void nand_reset();//复位
unsigned char read_data();//读数据
void nand_init();//初始化
void nand_read_id();//读ID
int nand_read(unsigned int *buf, unsigned long start_addr, int size);//完整的读
int nand_write(unsigned char *sdram_addr, unsigned long nand_addr, unsigned long size);//完整的写
unsigned char nand_erase(unsigned long block_num);//擦除去
 
#endif //_NAND_H_
